﻿<?php
session_start();
echo '<body bgcolor="#009900"><center><h2>文件已经上传</h2>';
if(isset($_SESSION["user"])==false){
	header("location:../login.php");
	exit;
}
$user=$_SESSION["user"];
if(isset($_SESSION["dir"])==false){
	header("location:index.php");
	exit;
}
$dir=$_SESSION["dir"];


if(($_FILES["file"]["size"] < 2000000)){
	$type=".jpg";
	/*if($_FILES["file"]["type"]=="image/gif"){
		$type=".gif";
	}else{
		$type=".jpg";
	}*/
	if(stripos($_FILES["file"]["name"],"png")){
		$type=".png";
	}else if(stripos($_FILES["file"]["name"],"gif")){
		$type=".gif";
	}else if(stripos($_FILES["file"]["name"],"bmp")){
		$type=".bmp";
	}else if(stripos($_FILES["file"]["name"],"zip")){
		$type=".zip";
	}else if(stripos($_FILES["file"]["name"],"rar")){
		$type=".rar";
	}else if(stripos($_FILES["file"]["name"],"7z")){
		$type=".7z";
	}else if(stripos($_FILES["file"]["name"],"htm")){
		$type=".htm";
	}else if(stripos($_FILES["file"]["name"],"html")){
		$type=".html";
	}else if(stripos($_FILES["file"]["name"],"swf")){
		$type=".swf";
	}else if(stripos($_FILES["file"]["name"],"css")){
		$type=".css";
	}else if(stripos($_FILES["file"]["name"],"js")){
		$type=".js";
	}else if(stripos($_FILES["file"]["name"],"txt")){
		$type=".txt";
	}else if(stripos($_FILES["file"]["name"],"cur")){
		$type=".cur";
	}
	$name=$_FILES["file"]["name"];
	//echo "##name:" . $name . "<br>";
	/******************************************************/
	if(strpos($name,";")===false){
		//die();
	/*************************这里是改的地方！！！******************************/
	//echo "##wait:" . $wait . "<br />";
	$wait=explode(".",$name);
	$okname=$wait[0];
	//echo "##name[0]:" . $wait[0] . "<br />";
	$okname=$okname . $type;
	//mkdir("./upload");
	//echo "##type:" . $type . "<br />";
	echo "上传文件名:" . $okname . "<br />";
	//echo "Upload: " . $_FILES["file"]["name"] . "<br />";
	echo "原来的扩展名： " . $_FILES["file"]["type"] . "<br />";
	echo "文件大小: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
	//echo "Stored in: " . $_FILES["file"]["tmp_name"];
	move_uploaded_file($_FILES["file"]["tmp_name"],"$user/$dir/" . $okname);
	echo '<br/><br/><a href="index.php?dir=' . $dir . '">返回</a>';
	
	$file=fopen("../log.txt","a");
	include '../lib/time.php';
	fwrite($file,"\r\n" . $time . ":'$user' in '$dir' upload file '$okname'.");


	header("location:index.php?dir=$dir");
	exit;
	}else{
		echo "呸呸呸，当我什么也没说。请不要欺负IIS的解析漏洞哦！！<br/>";
	}
}else{
	echo "呸呸呸，当我什么也没说。文件太大啦！！<br/>";
	echo '<a href="index.php?dir=' . $dir . '">返回</a>';
	exit;
}

?>
<!--<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file"><input type="submit">

</form>-->